<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html >
<html>
<head>
<%@ include file="/WEB-INF/view/jQgrid.jsp"%>
</head>
<body style="background-color: white;" class="gray-bg">
	<div class="ibox-content">
		<form class="form-horizontal m-t " id="signupForm" method="post"
			enctype="multipart/form-data">
							<div class="form-group">
				<label class="col-sm-3 control-label">请假类型：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="type" name="type" />
				</div>
			</div>
				<div class="form-group">
				<label class="col-sm-3 control-label">请假时间：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control datetime"  id="startDate" name="startDate" readonly="readonly"/>
				</div>
			</div>
				<div class="form-group">
				<label class="col-sm-3 control-label">结束时间：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control datetime" id="endDate" name="endDate" readonly="readonly"/>
				</div>
			</div>
				<div class="form-group">
				<label class="col-sm-3 control-label">请假时长：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="hours" name="hours" />
				</div>
			</div>
				<div class="form-group">
				<label class="col-sm-3 control-label">事由：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="particulars" name="particulars" />
				</div>
			</div>
			<div class="form-group" style="text-align: center;">
				<div class="col-sm-12">
					<button class="btn btn-primary" type="button" id="sub">提交</button>
				</div>
			</div>
		</form>
	</div>


	<script>
    $(function () {
    	//日期插件
	   	$(".datetime").datetimepicker({//选择年月日
	   			format: 'yyyy-mm-dd HH:mm:ss',
	   			language: 'zh-CN',
	   			weekStart: 1,
	   			todayBtn: 1,//显示‘今日’按钮
	   			autoclose: 1,
	   			todayHighlight: 1,
	   			startView: 2,
	   			minView: 2,  // Number, String. 默认值：0, 'hour'，日期时间选择器所能够提供的最精确的时间选择视图。
	   			clearBtn:true,//清除按钮
	   			forceParse: 0
	   	});
        $("#sub").click(function () {
        	//批量验证表单非空
			//调用方式
        	var arr=new Array(
        	  new Array('type','请假类型未填写!'),
        	  new Array('startDate','请假时间未填写!'),
        	  new Array('endDate','结束时间未填写!'),
        	  new Array('hours','请假时长未填写!'),
        	  new Array('particulars','事由未填写!')
        	)
        	  for(var i=0;i<arr.length;i++){
	        	  if($("#"+arr[i][0]).val()==''){
	        		  $("#"+arr[i][0]).tips({
	  					side:3,
	  		            msg:arr[i][1],
	  		            bg:'#AE81FF',
	  		            time:1
	  		        });
	        		  $("#"+arr[i][0]).focus();
	  				return;
	  			}
        	  }
        	var beginDate=$("#startDate").val();    
        	var endDate=$("#endDate").val();    
        	var d1 = new Date(beginDate.replace(/\-/g, "\/"));    
        	var d2 = new Date(endDate.replace(/\-/g, "\/")); 
        	if(beginDate!=""&&endDate!=""&&d1 >=d2) {    
        	    alert("开始时间不能大于结束时间！");    
        	    return false;    
        	}
            $("#signupForm").ajaxSubmit({
                url: '<%=contextPath%>/attendanceLeave/add',
					type : 'post',
					dataType : "json",
					success : function(data) {
						if (data.code == 200) {
							swal({
								title : data.message,
								type : "success",
								showCancelButton : false,
								confirmButtonText : "确定",
								animation : "slide-from-bottom",
								closeOnConfirm : true
							}, function() {
								top.Dialog.close();
							});
						} else {
							swal("错误", data.message, "error");
						}
					}
				});

			});
		});
	</script>
</body>
</html>